﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using HNQXYJ.BLL;

namespace HNQXYJ.DataCenterJS
{
    public partial class TerminalUpdateData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            
            if (!IsPostBack)
            {
                int id =  Convert.ToInt32(Request["id"]);
                string procName = "TerminalGetDataForUpdateById";
                SqlParameter[] paras = { 
                                       new SqlParameter("@Id",SqlDbType.Int)
                                       };
                paras[0].Value = id;
                DataTable dt = TerminalBLL.GetTerminalTable(procName, paras);
                foreach(DataRow dr in dt.Rows)
                {
                    this.txtPhone.Text = dr["Phone"].ToString();
                    this.txtTownName.Text = dr["TownName"].ToString();
                    this.txtLeader.Text = dr["Leader"].ToString();
                    this.txtLeaderPhone.Text = dr["LeaderPhone"].ToString();
                    this.txtStatus.Value = dr["Statuss"].ToString();
                    this.txtLng.Text = dr["Lng"].ToString();
                    this.txtLat.Text = dr["Lat"].ToString();
                    this.txtNotes.Text = dr["Notes"].ToString();
                }
            }
            
           
        }

        // 更新页面数据
        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            string procName = "TerminalUpdateDataById";
            int res = 0;
            SqlParameter[] paras = { 
                                 new SqlParameter("@Id",SqlDbType.Int),
                                 new SqlParameter("@Phone",SqlDbType.VarChar,50),
                                 new SqlParameter("@TownName",SqlDbType.NVarChar,50),
                                 new SqlParameter("@Leader",SqlDbType.NVarChar,50),
                                 new SqlParameter("@LeaderPhone",SqlDbType.NVarChar,50),
                                 new SqlParameter("@Statuss",SqlDbType.NVarChar,50),
                                 new SqlParameter("@Lng",SqlDbType.Float),
                                 new SqlParameter("@Lat",SqlDbType.Float),
                                 new SqlParameter("@Notes",SqlDbType.NVarChar,500)
                                 };
            paras[0].Value =Convert.ToInt32(Request["id"]);
            paras[1].Value = this.txtPhone.Text.Trim();
            paras[2].Value = this.txtTownName.Text.Trim();
            paras[3].Value = this.txtLeader.Text.Trim();
            paras[4].Value = this.txtLeaderPhone.Text.Trim();
            paras[5].Value = this.txtStatus.Value;
            paras[6].Value = Convert.ToDouble(this.txtLng.Text.Trim());
            paras[7].Value = Convert.ToDouble(this.txtLat.Text.Trim());
            paras[8].Value = this.txtNotes.Text.Trim();

             res = TerminalBLL.ExecNoQuery(procName, paras);
            if (res > 0)
            {
                //this.Label1.Text = "更新数据成功";
               Response.Redirect("../HN_Terminal/TerminalMgrRankLevel.aspx", true);
            }
            else
            {
                this.Label1.Text = "更新数据失败";
            }
        }

        //返回终端数据表
        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("../HN_Terminal/TerminalMgt.aspx", true);
        }
    }
}